<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="content-type" content="no-cache, must-revalidate"/>
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT"/>
    <title>提交作业</title>

    <link rel="stylesheet" href="css/my.css">
    <link href="/front/css/bootstrap.min.css" rel="stylesheet">

    <style>
        .nx-nav-container ul {
            width: 100%;
            height: 100%;
            margin: 0 auto;
            display: flex;
            justify-content: center;
        }

        .nx-nav-container ul li {
            display: inline-block;
            width: 120px;
            text-align: center;
            line-height: 45px;
        }

        .nx-nav-container a {
            color: #FFFFFF;
        }

        .nx-nav-container a:hover {
            color: aquamarine;
            text-decoration: none;
        }

        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div id="wrapper" v-cloak>
    <div class="nx-header">
        <div style="display: flex;width: 100%; height: 30px; line-height: 30px; background-color: #eee;">
            <div style="flex: 5; padding: 0 10px; color: orangered">
                欢迎访问 欢迎使用本系统
            </div>
            <div v-if="user.name" style="flex: 1">
                欢迎您：{{user.name}}
                <a style="margin-left: 30px; color: blue" href="javascript:void(0)" @click="logout">退出</a>
                <a v-if="isCollect" style="margin-left: 10px" href="collectInfo.html">收藏夹</a>
            </div>
        </div>
    </div>
    <div style="height: 80px; line-height: 80px;">
        <div style="margin-left: 20px; position: relative">
            <img src="img/logo1.png" alt="" style="width: 40px; position: absolute; top: 20px">
            <b style="margin-left:45px;font-size: 25px; text-shadow: 5px 5px 3px #888888;">欢迎使用本系统</b>
        </div>
    </div>

    <div class="nx-nav-container" style="height: 45px; background-color: black">
        <ul>
            <li><a href="index.html">首页</a></li>
            <li><a href="advertiserInfo.html" >公告信息</a></li>
			<li><a href="fileInfo.html">资料信息</a></li>
			<li class="active"><a href="zuoyeInfo.html">提交作业</a></li>

            <li v-if="isShow"><a href="/end/page/index.html" target="_blank">进入后台系统</a></li>
            <li><a href="/end/page/login.html" target="_blank">登录</a></li>
            <li><a href="/end/page/register.html" target="_blank">注册</a></li>
        </ul>
    </div>
    <div class="container"  style="margin-top: 20px">
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover">
                <thead>
                <tr style="background-color: #f5f5f5">
<!--                    <th style="width: 50px">ID</th>-->
					<th>名称</th>
					<th>发布时间</th>
					<th>作业</th>

                    <th>发布人</th>
                    <th>详情</th>
                    <th v-if="isReserver">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(data,index) in tableData" :key="data.id">
<!--                    <td>{{data.id}}</td>-->
					<td>{{data.name}}</td>
					<td>{{data.time}}</td>
					<td>{{data.zuoye}}</td>

                    <td>{{data.publishName}}</td>
                    <td><a :href=`zuoyeInfoDetail.html?id=${data.id}` target="_blank">详情</a></td>
                    <td v-if="isReserver">
                        <div v-if="reserveUpload" style="position: relative; width: 60px; height: 20px; float: left">
                            <button class="btn btn-xs btn-primary"
                                    style="position:absolute"
                                    :disabled="(data.reserveStatus == '审核通过' || data.reserveStatus == '待审核') && isSingle"
                            >
                                上传
                            </button>
                            <input :disabled="(data.reserveStatus == '审核通过' || data.reserveStatus == '待审核') && isSingle"
                                   @change="upload" type="file" ref="file" multiple
                                   style="position:absolute;opacity:0;width:36px;height:18px;">
                        </div>
                        <button class="btn btn-primary btn-xs"
                                :disabled="(data.reserveStatus == '审核通过' || data.reserveStatus == '待审核') && isSingle"
                                @click="reserve(data)">
                            提交
                        </button>
                    </td>
                </tr>
                </tbody>
            </table>
            <div style="text-align: center;">
                <nav aria-label="Page navigation example">
                    <ul class="pagination">
                        <li class="page-item" :class="{ disabled: preActive }">
                            <a class="page-link" href="javascript:void(0)"
                               @click="loadTable(pageInfo.pageNum - 1)">上一页</a>
                        </li>
                        <li class="page-item">
                            <a class="page-link" href="javascript:void(0)" v-if="pageInfo.pageNum > 1" @click="loadTable(pageInfo.pageNum - 1)">{{pageInfo.pageNum - 1}}</a>
                        </li>
                        <li class="page-item disabled">
                            <a class="page-link" aria-disabled="true" href="javascript:void(0)">{{pageInfo.pageNum}}</a>
                        </li>
                        <li class="page-item">
                            <a class="page-link" href="javascript:void(0)" v-if="pageInfo.hasNextPage" @click="loadTable(pageInfo.pageNum + 1)">{{pageInfo.pageNum + 1}}</a>
                        </li>
                        <li class="page-item" :class="{ disabled: nextActive }">
                            <a class="page-link" href="javascript:void(0)" @click="loadTable(pageInfo.hasNextPage? (pageInfo.pageNum + 1) : pageInfo.pageNum)">下一页</a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>

<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>

<script>
    new Vue({
        el: '#wrapper',
        data: {
            user: {},
            isShow: false,
            tableData: [],
            pageInfo: {},
            preActive: true,
            nextActive: true,
            fileId: 0,
            fileName: '',
            isReserver: false,
            isSingle: false,
            reserveUpload: true,
            isCollect: false
        },

        created: function() {
            axios.get('/auth').then(res => {
                if (res.data.code === '0') {
                    this.user = res.data.data;
                    this.isShow = true;
                }
            });
            axios.get("/permission/6").then(res => {
                if (res.data.code === '0') {
                    this.permission = res.data.data;
                    // 确定当前用户身份
                    this.user = JSON.parse(localStorage.getItem("user"));
                    if (this.permission.indexOf(1) === -1) {
                        this.isReserver = true;
                    }
                    // 加载页面
                    this.loadTable(1);
                } else {
                    alert(res.data.msg);
                }
            });
        },

        methods: {
            loadTable(pageNum) {
                axios.get("/zuoyeInfo/page?pageSize=10&pageNum=" + pageNum).then(res => {
                    if (res.data.code === '0') {
                        this.tableData = res.data.data.list;
                        this.pageInfo = res.data.data;
                        this.preActive = !(this.pageInfo.hasPreviousPage);
                        this.nextActive = !(this.pageInfo.hasNextPage);
                    } else {
                        alert(res.data.msg);
                    }
                });
            },

            reserve(data) {
                data.fileId = this.fileId;
                data.fileName = this.fileName;
                axios.post('/zuoyeInfo/reserve', data).then(res => {
                    if (res.data.code === '0') {
                        alert('提交成功，等待管理员审核，可以在后台查看审核结果');
                        this.loadTable(1);
                    } else {
                        alert(res.data.msg);
                    }
                })
            },
            upload: function () {
                let files = this.$refs.file[0].files;
                for (let i = 0; i < files.length; i++) {
                    let formData = new FormData();
                    formData.append('file', files[i]);
                    axios.post('/files/upload', formData, {
                        'Content-Type': 'multipart/form-data'
                    }).then(res => {
                        if (res.data.code === '0') {
                            alert('文件上传成功');
                            this.fileId = res.data.data.id;
                            this.fileName = res.data.data.originName;
                        } else {
                            alert(res.data.msg);
                        }
                    })
                }
            },
            logout() {
                axios.get("/logout").then(res => {
                    if(res.data.code === '0') {
                        location.href = '/front/index.html';
                    } else {
                        msg('error', res.data.msg);
                    }
                })
            }
        }
    })
</script>
</body>
</html>
